﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestSystem.Domain.Abstract;
using TestSystem.Domain.Entities;

namespace TestSystem.Controllers.Administrator
{
    public class CategoriesController : Controller
    {
        private ICategoryRepository _categoryRepository;

        public CategoriesController(ICategoryRepository categoryRepository)
        {
            _categoryRepository = categoryRepository;
        }

        public ActionResult Index()
        {
            return View(_categoryRepository.Categories.ToList());
        }

        public ActionResult addNewCategory()
        {
            return View(new Category());
        }

        [HttpPost]
        public ActionResult addNewCategory(Category category)
        {
            _categoryRepository.add(category);
            return RedirectToAction("Index");
        }

         [HttpPost]
        public ActionResult Remove(int id)
        {
            _categoryRepository.RemoveCategory(id);

            var results = new 
            {
                Message = "Pomyślnie usunięto stanowisko.",
                ItemCount = _categoryRepository.PositionAmount(),
                DeleteId = id
            };
            return Json(results);
        }
    }
}
